
#include "Input.h"
#include "assert.h"

bool Input::initialise()
{	
	return true;
}

void Input::keyInput( bool down, int wParam )
{
	if( down )
		mKeys[wParam] = keyPressed;
	else
		mKeys[wParam] = keyReleased;
}

bool Input::assignActionToKey( int action, int key )
{
	assert( key < NUMKEYS && "key input outof range" );
	// search through loaded actions see if alrdy there
	std::map<int, int>::iterator searchIter;
	//m_loadedTextures[fileS];
	searchIter = mActionMap.find( action );
	if( searchIter != mActionMap.end() )
		return false;

	mActionMap.insert( std::pair<int, int>(action,key) );
	return true;
}

void Input::removeAction( int action )
{
	auto const iter = mActionMap.find( action );
	if ( iter != mActionMap.end( ) )
	{
		mActionMap.erase( iter );
	}
}

void Input::clearActionAssignments()
{
	mActionMap.clear();
}


inputReturnData Input::getActionInput( int action )
{
	// search through loaded actions see if alrdy there
	// shouldnt be enough actions in that it'll harm speed because called not"too many" times
	std::map<int, int>::iterator searchIter;
	searchIter = mActionMap.find( action );

	if( searchIter != mActionMap.end() )
	{
		if( mKeys[searchIter->second] == keyPressed || mKeys[searchIter->second] == keyHeld )
			return inputReturnData( mKeys[searchIter->second], 1 );
		else
			return inputReturnData( mKeys[searchIter->second], 0 );
	}

	return inputReturnData( keyNA, 0 );
}
void Input::update()
{
	for( int i = 0; i < NUMKEYS; ++i )
	{
		if(mKeys[i] == keyPressed )
			mKeys[i] = keyHeld;
		else if( mKeys[i] == keyReleased )
			mKeys[i] = keyNA;
	}
}

Input::~Input()
{
}

